import request from '@/utils/request';
import { PermissionTableListParams, PermissionTableListItem } from './permissionData.d';



/**
 * 根据条件分页查询权限列表
 * @param params 查询条件
 */
export async function queryPermission(params?: PermissionTableListParams) {
    return request('/api/ums/permission', {
        method: 'GET',
        params,
    });
}


/**
 * 新增权限
 * @param params /api/ums/permissionTableListItem
 */
export async function addPermission(params: PermissionTableListItem) {
    return request('/api/ums/permission', {
        method: 'POST',
        data: {
            ...params,
        },
    });
}

/**
 * 更新权限
 * @param params /api/ums/permissionTableListItem
 */
export async function updatePermission(params: PermissionTableListParams) {
    return request(`/api/ums/permission/${params.permissionId}`, {
        method: 'PUT',
        data: {
            ...params,
        },
    });
}
/**
 * 更新按钮权限
 * @param params /api/ums/permissionTableListItem
 */
export async function updatePermissionButtons(params: {
    parentId: string,
    buttonPermissions: string[]
}) {
    return request(`/api/ums/permission/buttons`, {
        method: 'POST',
        data: {
            ...params,
        },
    });
}


/**
 * 详情权限
 * @param params 主键
 */
export async function getPermission(params:{ id: string|undefined }) {
    return request(`/api/ums/permission/${params.id}`, {
        method: 'GET',
    });
}

/**
 * 删除权限
 * @param params 主键
 */
export async function removePermission(params: { id: string|undefined }) {
    return request(`/api/ums/permission/${params.id}`, {
        method: 'DELETE',
        data: {
            ...params,
            method: 'DELETE',
        },
    });
}

/**
 * 删除权限
 * @param params 主键数组
 */
export async function removeBatchPermission(params: { ids: (string|undefined)[] }) {
    return request('/api/ums/permission', {
        method: 'DELETE',
        data: {
            ...params,
            method: 'DELETE',
        },
    });
}
